
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Will
 */
public class tablaCliente extends javax.swing.JFrame {
Funciones f=new Funciones();
DefaultTableModel dt=new DefaultTableModel();
Connection conn;
   ResultSet rs;
   Statement stmt;
   int cambioTF=1; //Controla la busqueda del tfBuscar para clientes activos y desactivados: ACtivo=1,Inactivo=0
   int AoM=0; //AoM=Agregar o Modificar: variable que controla si se agrega o modifica en el jDialog Agregar=0,Modificar=1
    /**   
     * Creates new form tablaCliente
     */
    public tablaCliente() {
        initComponents();
        
        dt.addColumn("Código");
        dt.addColumn("Nombre");
        dt.addColumn("Primer Apellido");
        dt.addColumn("Segundo Apellido");
        dt.addColumn("Dirección");
        tablaClientes.setModel(dt);
        tablaClientes.removeColumn(tablaClientes.getColumn(0));
        btnDarAlta.setVisible(false);
        btnAtras.setVisible(false);
        String sql="SELECT * FROM clientes WHERE activo=1"; 
        mostrarTabla(sql);
        
    }
    
    public void mostrarTabla(String sql){
        conn=Conexion.obtenerConexion();
        dt.setRowCount(0);
        try {
            stmt=conn.createStatement();
            rs=stmt.executeQuery(sql);
            while(rs.next()){
                dt.addRow(new Object[]{rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5)});
            }
            conn.close();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error al mostrar tabla","ERROR",JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jdAccion = new javax.swing.JDialog();
        panelRect4 = new org.edisoncor.gui.panel.PanelRect();
        lblTitulo = new org.edisoncor.gui.label.LabelMetric();
        panelRect5 = new org.edisoncor.gui.panel.PanelRect();
        panelCurves2 = new org.edisoncor.gui.panel.PanelCurves();
        btnGuardar = new org.edisoncor.gui.button.ButtonIpod();
        btnCancelar = new org.edisoncor.gui.button.ButtonIpod();
        btnLimpiar = new org.edisoncor.gui.button.ButtonIpod();
        panelRound = new org.edisoncor.gui.panel.PanelRound();
        labelMetric8 = new org.edisoncor.gui.label.LabelMetric();
        labelMetric9 = new org.edisoncor.gui.label.LabelMetric();
        labelMetric10 = new org.edisoncor.gui.label.LabelMetric();
        labelMetric11 = new org.edisoncor.gui.label.LabelMetric();
        tfNombre = new org.edisoncor.gui.textField.TextFieldRectBackground();
        tfPApellido = new org.edisoncor.gui.textField.TextFieldRectBackground();
        tfSApellido = new org.edisoncor.gui.textField.TextFieldRectBackground();
        tfDireccion = new org.edisoncor.gui.textField.TextFieldRectBackground();
        panelRect1 = new org.edisoncor.gui.panel.PanelRect();
        lbClientes = new org.edisoncor.gui.label.LabelMetric();
        panelRect2 = new org.edisoncor.gui.panel.PanelRect();
        panelCurves1 = new org.edisoncor.gui.panel.PanelCurves();
        btnNuevo = new org.edisoncor.gui.button.ButtonIpod();
        btnModificar = new org.edisoncor.gui.button.ButtonIpod();
        buttonIpod4 = new org.edisoncor.gui.button.ButtonIpod();
        btnDarBaja = new org.edisoncor.gui.button.ButtonIpod();
        panelRect3 = new org.edisoncor.gui.panel.PanelRect();
        tfBuscar = new java.awt.TextField();
        labelMetric3 = new org.edisoncor.gui.label.LabelMetric();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaClientes = new org.jdesktop.swingx.JXTable();
        btnDarAlta = new org.edisoncor.gui.button.ButtonIpod();
        btnAtras = new org.edisoncor.gui.button.ButtonIpod();

        jdAccion.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jdAccion.setModal(true);

        panelRect4.setColorPrimario(new java.awt.Color(0, 204, 204));

        lblTitulo.setText("=)");
        lblTitulo.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        panelRect4.add(lblTitulo);

        jdAccion.getContentPane().add(panelRect4, java.awt.BorderLayout.NORTH);

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/guardar.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/limpiar.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelCurves2Layout = new javax.swing.GroupLayout(panelCurves2);
        panelCurves2.setLayout(panelCurves2Layout);
        panelCurves2Layout.setHorizontalGroup(
            panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCurves2Layout.createSequentialGroup()
                .addGap(130, 130, 130)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelCurves2Layout.setVerticalGroup(
            panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCurves2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelRound.setColorPrimario(new java.awt.Color(0, 0, 0));
        panelRound.setColorSecundario(java.awt.Color.green);
        panelRound.setGradiente(org.edisoncor.gui.panel.Panel.Gradiente.CENTRAL);

        labelMetric8.setText("Nombre(s):");

        labelMetric9.setText("Primer Apellido:");

        labelMetric10.setText("Segundo Apellido:");

        labelMetric11.setText("Dirección:");

        tfNombre.setDescripcion("Ingrese el texto aquí");
        tfNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfNombreKeyTyped(evt);
            }
        });

        tfPApellido.setDescripcion("Ingrese el texto aquí");
        tfPApellido.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfPApellidoKeyTyped(evt);
            }
        });

        tfSApellido.setDescripcion("Ingrese el texto aquí");
        tfSApellido.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfSApellidoKeyTyped(evt);
            }
        });

        tfDireccion.setDescripcion("Ingrese el texto aquí");

        javax.swing.GroupLayout panelRoundLayout = new javax.swing.GroupLayout(panelRound);
        panelRound.setLayout(panelRoundLayout);
        panelRoundLayout.setHorizontalGroup(
            panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRoundLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelRoundLayout.createSequentialGroup()
                        .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelMetric10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelMetric11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelRoundLayout.createSequentialGroup()
                                .addComponent(tfSApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(176, Short.MAX_VALUE))
                            .addGroup(panelRoundLayout.createSequentialGroup()
                                .addComponent(tfDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(23, 23, 23))))
                    .addGroup(panelRoundLayout.createSequentialGroup()
                        .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelMetric8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelMetric9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(21, 21, 21)
                        .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfPApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(23, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        panelRoundLayout.setVerticalGroup(
            panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRoundLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfPApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfSApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(panelRoundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelRect5Layout = new javax.swing.GroupLayout(panelRect5);
        panelRect5.setLayout(panelRect5Layout);
        panelRect5Layout.setHorizontalGroup(
            panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect5Layout.createSequentialGroup()
                .addGroup(panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelRect5Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(panelRound, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 14, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRect5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panelCurves2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelRect5Layout.setVerticalGroup(
            panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect5Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(panelRound, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addComponent(panelCurves2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jdAccion.getContentPane().add(panelRect5, java.awt.BorderLayout.CENTER);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        panelRect1.setColorPrimario(new java.awt.Color(0, 204, 204));

        lbClientes.setText("CLIENTES");
        lbClientes.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        panelRect1.add(lbClientes);

        getContentPane().add(panelRect1, java.awt.BorderLayout.PAGE_START);

        panelRect2.setColorPrimario(new java.awt.Color(0, 102, 204));
        panelRect2.setColorSecundario(new java.awt.Color(0, 204, 204));

        panelCurves1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/add.png"))); // NOI18N
        btnNuevo.setText("Nuevo");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });
        panelCurves1.add(btnNuevo, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 0, 60, 60));

        btnModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/preferences-composer.png"))); // NOI18N
        btnModificar.setText("Modificar");
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });
        panelCurves1.add(btnModificar, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 0, 70, 60));

        buttonIpod4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/ver.png"))); // NOI18N
        buttonIpod4.setText("Ver Bajas");
        buttonIpod4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonIpod4ActionPerformed(evt);
            }
        });
        panelCurves1.add(buttonIpod4, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, -10, 70, 70));

        btnDarBaja.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/bajas.png"))); // NOI18N
        btnDarBaja.setText("Dar Baja");
        btnDarBaja.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDarBajaActionPerformed(evt);
            }
        });
        panelCurves1.add(btnDarBaja, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, -10, 70, 70));

        panelRect3.setColorPrimario(new java.awt.Color(0, 51, 204));
        panelRect3.setColorSecundario(new java.awt.Color(0, 153, 153));

        tfBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfBuscarKeyReleased(evt);
            }
        });

        labelMetric3.setText("Buscar");

        tablaClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tablaClientes);

        btnDarAlta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/altas.png"))); // NOI18N
        btnDarAlta.setText("Dar Alta");
        btnDarAlta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDarAltaActionPerformed(evt);
            }
        });

        btnAtras.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancelar.png"))); // NOI18N
        btnAtras.setText("Atrás");
        btnAtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtrasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelRect3Layout = new javax.swing.GroupLayout(panelRect3);
        panelRect3.setLayout(panelRect3Layout);
        panelRect3Layout.setHorizontalGroup(
            panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect3Layout.createSequentialGroup()
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(panelRect3Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAtras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDarAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(124, 124, 124)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 428, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(205, 205, 205)
                            .addComponent(labelMetric3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(26, 26, 26)
                            .addComponent(tfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(25, 25, 25)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 593, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        panelRect3Layout.setVerticalGroup(
            panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect3Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMetric3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDarAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAtras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout panelRect2Layout = new javax.swing.GroupLayout(panelRect2);
        panelRect2.setLayout(panelRect2Layout);
        panelRect2Layout.setHorizontalGroup(
            panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect2Layout.createSequentialGroup()
                .addGroup(panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelCurves1, javax.swing.GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE)
                    .addGroup(panelRect2Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(panelRect3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelRect2Layout.setVerticalGroup(
            panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRect2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(panelRect3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelCurves1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        getContentPane().add(panelRect2, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDarBajaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDarBajaActionPerformed
        // TODO add your handling code here:
        darBaja();
        
    }//GEN-LAST:event_btnDarBajaActionPerformed

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        // TODO add your handling code here:
            AoM=0;
            lblTitulo.setText("Agregar Cliente");
            jdAccion.pack();
            jdAccion.setLocationRelativeTo(this);
            jdAccion.setVisible(true);
            tfNombre.setText("");
            tfPApellido.setText("");
            tfSApellido.setText("");
            tfDireccion.setText("");
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void buttonIpod4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonIpod4ActionPerformed
        // TODO add your handling code here:
        cambioTF=0;//tfBuscar busca solo clientes desactivados
       
        btnDarAlta.setVisible(true);
        btnAtras.setVisible(true);
        String sql="SELECT * FROM clientes WHERE activo=0";
        mostrarTabla(sql);
        btnModificar.setEnabled(false);
        btnDarBaja.setEnabled(false);
        btnNuevo.setEnabled(false);
    }//GEN-LAST:event_buttonIpod4ActionPerformed

    private void btnDarAltaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDarAltaActionPerformed
        // TODO add your handling code here:
       darAlta();
    }//GEN-LAST:event_btnDarAltaActionPerformed

    private void btnAtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtrasActionPerformed
        // TODO add your handling code here:
        cambioTF=1;//tfBuscar busca solo clientes activados
       
        String sql="SELECT * FROM clientes WHERE activo=1"; 
        mostrarTabla(sql);
        btnDarAlta.setVisible(false);
        btnAtras.setVisible(false);
        btnModificar.setEnabled(true);
        btnDarBaja.setEnabled(true);
        btnNuevo.setEnabled(true);
    }//GEN-LAST:event_btnAtrasActionPerformed

    private void tfBuscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfBuscarKeyReleased
        // TODO add your handling code here:
        String nombre=tfBuscar.getText();
        String sql;
        if(cambioTF==1){
            sql="SELECT * FROM clientes where (nombre like '%"+nombre+"%' or primerApellido like '%"+nombre+"%' or segundoApellido like '%"+nombre+"%') && activo=1";
        }else{
            sql="SELECT * FROM clientes where (nombre like '%"+nombre+"%' or primerApellido like '%"+nombre+"%' or segundoApellido like '%"+nombre+"%') && activo=0";
        }
        
        mostrarTabla(sql);
    }//GEN-LAST:event_tfBuscarKeyReleased

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        // TODO add your handling code here:
        AoM=1;
        lblTitulo.setText("Modificar Datos de Cliente");
        //Recupero los datos de la BD para llenar los textfield
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaClientes.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="SELECT * FROM clientes WHERE codCliente='"+codigo+"'";

            conn=Conexion.obtenerConexion();
            try {
                stmt=conn.createStatement();
                rs=stmt.executeQuery(sql);
                while(rs.next()){
                    tfNombre.setText(rs.getString(2));
                    tfPApellido.setText(rs.getString(3));
                    tfSApellido.setText(rs.getString(4));
                    tfDireccion.setText(rs.getString(5));
                }
                conn.close();
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "Error al buscar: "+ex);
            }
            
            jdAccion.pack();
            jdAccion.setLocationRelativeTo(this);
            jdAccion.setVisible(true);
            
            
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un cliente");
        }
    }//GEN-LAST:event_btnModificarActionPerformed

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        // TODO add your handling code here:
        tfNombre.setText("");
        tfPApellido.setText("");
        tfSApellido.setText("");
        tfDireccion.setText("");
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        jdAccion.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        if(AoM==0){
            
            String nom=tfNombre.getText();
            String apell1=tfPApellido.getText();
            String apell2=tfSApellido.getText();//OPCIONAL
            String dire=tfDireccion.getText();
            if(nom.equals("")||apell1.equals("")||dire.equals("")){
                JOptionPane.showMessageDialog(null, "Sólo el campo segundo apellido no es obligatorio, Complete los demás campos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
            }else{
                String sql="INSERT INTO clientes(nombre,primerApellido,segundoApellido,direccion,activo) VALUES('"+nom+"','"+apell1+"','"+apell2+"','"+dire+"','1')";
                f.insertar(sql);
                
            }
            
        }else{
            String nombre, primer, segundo, dir;
            nombre = tfNombre.getText();
            primer = tfPApellido.getText();
            segundo = tfSApellido.getText();//OPCIONAL
            dir = tfDireccion.getText();
            int codigo = Integer.parseInt(dt.getValueAt(tablaClientes.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            if (nombre.equals("") || primer.equals("") || dir.equals("")) {
                JOptionPane.showMessageDialog(null, "Sólo el campo segundo apellido no es obligatorio, Complete los demás campos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
            } else {
                String sql = "UPDATE clientes SET nombre='" + nombre + "', primerApellido='" + primer + "', segundoApellido='" + segundo + "',direccion='" + dir + "' WHERE codCliente='" + codigo + "'";
                f.insertar(sql);

            }
        }
        f.cerrarConexion();
        mostrarTabla("SELECT * FROM clientes WHERE activo=1");
        jdAccion.dispose();
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void tfNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfNombreKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) && (c == KeyEvent.VK_DELETE) || (c == KeyEvent.VK_UP))) {
            getToolkit().beep();
            evt.consume();

        }
    }//GEN-LAST:event_tfNombreKeyTyped

    private void tfPApellidoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfPApellidoKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) && (c == KeyEvent.VK_DELETE) || (c == KeyEvent.VK_UP))) {
            getToolkit().beep();
            evt.consume();

        }
    }//GEN-LAST:event_tfPApellidoKeyTyped

    private void tfSApellidoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfSApellidoKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) && (c == KeyEvent.VK_DELETE) || (c == KeyEvent.VK_UP))) {
            getToolkit().beep();
            evt.consume();

        }
    }//GEN-LAST:event_tfSApellidoKeyTyped

    private void darBaja(){
        
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaClientes.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="UPDATE clientes SET activo='0' WHERE codCliente='"+codigo+"'";
            f.insertar(sql);
            sql="SELECT * FROM clientes WHERE activo=1"; 
            mostrarTabla(sql);
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un cliente");
        }
        
    }
    private void darAlta(){
       
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaClientes.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="UPDATE clientes SET activo='1' WHERE codCliente='"+codigo+"'";
            f.insertar(sql);
            sql="SELECT * FROM clientes WHERE activo=0"; 
            mostrarTabla(sql);
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un cliente");
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
       
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(tablaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(tablaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(tablaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(tablaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
             

                new tablaCliente().setVisible(true);
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.edisoncor.gui.button.ButtonIpod btnAtras;
    private org.edisoncor.gui.button.ButtonIpod btnCancelar;
    private org.edisoncor.gui.button.ButtonIpod btnDarAlta;
    private org.edisoncor.gui.button.ButtonIpod btnDarBaja;
    private org.edisoncor.gui.button.ButtonIpod btnGuardar;
    private org.edisoncor.gui.button.ButtonIpod btnLimpiar;
    private org.edisoncor.gui.button.ButtonIpod btnModificar;
    private org.edisoncor.gui.button.ButtonIpod btnNuevo;
    private org.edisoncor.gui.button.ButtonIpod buttonIpod4;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JDialog jdAccion;
    private org.edisoncor.gui.label.LabelMetric labelMetric10;
    private org.edisoncor.gui.label.LabelMetric labelMetric11;
    private org.edisoncor.gui.label.LabelMetric labelMetric3;
    private org.edisoncor.gui.label.LabelMetric labelMetric8;
    private org.edisoncor.gui.label.LabelMetric labelMetric9;
    private org.edisoncor.gui.label.LabelMetric lbClientes;
    private org.edisoncor.gui.label.LabelMetric lblTitulo;
    private org.edisoncor.gui.panel.PanelCurves panelCurves1;
    private org.edisoncor.gui.panel.PanelCurves panelCurves2;
    private org.edisoncor.gui.panel.PanelRect panelRect1;
    private org.edisoncor.gui.panel.PanelRect panelRect2;
    private org.edisoncor.gui.panel.PanelRect panelRect3;
    private org.edisoncor.gui.panel.PanelRect panelRect4;
    private org.edisoncor.gui.panel.PanelRect panelRect5;
    private org.edisoncor.gui.panel.PanelRound panelRound;
    private org.jdesktop.swingx.JXTable tablaClientes;
    private java.awt.TextField tfBuscar;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfDireccion;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfNombre;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfPApellido;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfSApellido;
    // End of variables declaration//GEN-END:variables
}
